<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
    <title>User list</title>
    <script type="text/javascript" src="../../js/include.js"></script>
    <script type="text/javascript">
        //删除
        function del(){
            var row = $("#dg").datagrid('getSelections');
            if(row.length!=0) {
                $.messager.confirm("确认", "确认删除吗？", function (r) {
                    if (r) {
                        var myArray=new Array();
                        for(var i=0;i<row.length;i++){
                            myArray.push(row[i].id);
                        }
                        $.ajax({
                            url:url+'/system/product/delete',
                            type:'post',
                            data:"id="+myArray,
                            success:function(data){

                                if(data.result=="success"){
                                    window.location=htmlURL+"/system/product/list.html";
                                }else{
                                    $.messager.alert('提示',data.msg);
                                }
                            }
                        });
                    }
                });
            }else{
                $.messager.alert('提示','请选择一条');
            }
        }
        //查询
        function cx(){
            var obj=$("#searchFrom").serializeObject();
            $.ajax({
                url:url+"/system/product/query",
                data:obj,
                type:'post',
                success:function(data){
                    $('#dg').datagrid('loadData',data.data.rows);
                }
            });
        }
        //弹窗修改
        function upd(){
            var row =  $("#dg").datagrid('getSelections');
            if(row.length==1){
                window.location=htmlURL+"/system/product/update.html?id="+row[0].id;
            }else{
                $.messager.alert('提示','请选择一条');
            }
        }
        //增加
        function add(){
            window.location=htmlURL+"/system/product/add.html";
        }

        $(function(){
            if(!getResources("/system/product/add")){
                $('#add').hide();
            }

            if(!getResources("/system/product/update")){
                $('#update').hide();
            }

            if(!getResources("/system/product/delete")){
                $('#delete').hide();
            }
            cx();
        });
    </script>
</head>
<body>

<table id="dg"  class="easyui-datagrid"  fit="true"

       toolbar="#toolbar" pagination="true"
       rownumbers="true" fitColumns="true" singleSelect="false" >
    <thead>
    <tr>
        <th field=""  data-options="checkbox:true"></th>
        <th field="id" width="50">ID</th>
        <th field="name" width="50">名称</th>
        <th field="sort" width="50">类别</th>
        <th field="type" width="50">型号</th>
        <th field="entrance" width="50">操作入口</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <form id="searchFrom" action="">
        名称:<input type="text" name="name" class="easyui-validatebox" />
        类型:<input type="text" name="sort" class="easyui-validatebox" />
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="cx()">查询</a><br>
    </form>
    <a id="add" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>
    <a id="update" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="upd()">编辑</a>
    <a id="delete" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除</a>
</div>

</body>
</html>